<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">值班管理-值班计划</div>
      </div>
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-top">今日计划目标</div>
        <div class="x-pro-row">
          <div class="x-pro-label">计划销售额</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入" v-model="planmoney" :disabled="isfromindex" type="number"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">预估销售额</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入" v-model="ifmoney" :disabled="isfromindex" type="number"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">达成策略</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入" v-model="okplan" :disabled="isfromindex" type="textarea" :rows="3"></el-input>
          </div>
        </div>
        <div class="x-for-border" v-for="(item,index) in selltarget" :key="item.key">
          <div class="x-pro-row x-pro-rowblock">
            <div class="x-pro-label">其他销售目标</div>
            <div class="x-pro-input">
              <el-input placeholder="请输入" v-model="item.content" :disabled="isfromindex" type="textarea" :rows="3"></el-input>
            </div>
          </div>
          <div class="x-pro-remove" @click="removeselltarget(index)" v-show="!isfromindex">删除</div>
        </div>
        <div class="x-pro-addbox" @click="goonentrywork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加其他销售目标</div>
      </div>
      <!-- 今日追踪工作 -->
      <div class="x-pro-list">
        <div class="x-pro-top">今日追踪工作</div>
        <div  v-for="(item,index) in todaygowork" :key="item.key" class="x-for-border">
          <div class="x-pro-row">
            <div class="x-pro-label">追踪项目：</div>
            <div class="x-pro-input">
              <el-input placeholder="请输入" v-model="item.title" :disabled="isfromindex"></el-input>
            </div>
          </div>
          <div class="x-pro-row">
            <div class="x-pro-label">达到效果：</div>
            <div class="x-pro-input">
              <el-input placeholder="请输入" v-model="item.effect" :disabled="isfromindex"></el-input>
            </div>
          </div>
          <div class="x-pro-remove" @click="removetodaygowork(index)" v-show="!isfromindex">删除</div>
        </div>
        <div class="x-pro-addbox" @click="addtodaygowork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加</div>
      </div>
      <!-- 今日待办任务 -->
      <div class="x-pro-list">
        <div class="x-pro-top">今日待办任务</div>
        <div  v-for="(item,index) in todayneedwork" :key="item.key" class="x-for-border">
          <div class="x-pro-row">
            <div class="x-pro-label">任务名称</div>
            <div class="x-pro-input">
              <el-input placeholder="请输入" v-model="item.title" :disabled="isfromindex"></el-input>
            </div>
          </div>
          <div class="x-pro-row">
            <div class="x-pro-label">优先级：</div>
            <div class="x-pro-input">
              <template>
                <el-radio v-model="item.level" label="1" :disabled="isfromindex">A</el-radio>
                <el-radio v-model="item.level" label="2" :disabled="isfromindex">B</el-radio>
                <el-radio v-model="item.level" label="3" :disabled="isfromindex">C</el-radio>
              </template>
            </div>
          </div>
          <div class="x-pro-row">
            <div class="x-pro-label">责任人</div>
            <div class="x-pro-input">
              <el-select v-model="item.memberid" placeholder="请选择" @change="" :disabled="isfromindex">
                <el-option v-for="item in persondata" :key="item.id" :label="item.username" :value="item.id"></el-option>
              </el-select>
            </div>
          </div>
          <div class="x-pro-row">
            <div class="x-pro-label">完成时间</div>
            <div class="x-pro-input">
              <el-date-picker v-model="item.times" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" :disabled="isfromindex" :editable="notkey"></el-date-picker>
            </div>
          </div>
          <div class="x-pro-remove" @click="removetodayneedwork(index)" v-show="!isfromindex">删除</div>
        </div>
        <div class="x-pro-addbox" @click="addtodayneedwork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加</div>
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          isfromindex:false,
          planmoney:'',
          ifmoney:'',
          okplan:'',
          selltarget:[{
            'content':'',
            'index':0
          }],
          entryworkindex:0,
          todaygowork:[{
            title:'',
            effect:'',
            index:0
          }],
          todaygoworkindex:0,
          todayneedwork:[{
            'title':'',
            'level':'',
            'memberid':'',
            'times':'',
            'index':0
          }],
          notkey:false,
          persondata:[],
          todayneedworkindex:0,


        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;

        that.getperson()
        that.getdata()

      },
      methods: {
        getdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/content',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:''
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                if(ret.data.data!=''){//只读
                  that.isfromindex = true;

                  that.planmoney = ret.data.data.plan_sale;
                  that.ifmoney = ret.data.data.rate_sale;
                  that.okplan = ret.data.data.tactics;
                  that.selltarget = ret.data.target;
                  that.todaygowork = ret.data.follow;
                  that.todayneedwork = ret.data.task;
                }



              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getperson:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/list',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              // console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.persondata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        isok:function(){
          let that=this;
          console.log(that.planmoney);
          console.log(that.ifmoney);
          console.log(that.okplan);
          console.log(JSON.stringify(that.selltarget));
          console.log(JSON.stringify(that.todaygowork));
          console.log(JSON.stringify(that.todayneedwork));
          api.ajax({
            url:baseurl+'api/duty/addContent',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                plan_sale:that.planmoney,
                rate_sale:that.ifmoney,
                tactics:that.okplan,
                target_json:that.selltarget,
                follow_json:that.todaygowork,
                task_json:that.todayneedwork
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.confirm({
                    title: '提交成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){

                    }else{
                      api.closeWin({});

                    }
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //继续添加
        goonentrywork:function(){
          var that = this;
          that.entryworkindex++
          that.selltarget.push({
            'content':'',
            'index':that.entryworkindex,
          });
        },
        //
        addtodaygowork:function(){
          var that = this;
          that.todaygoworkindex++
          that.todaygowork.push({
            'title':'',
            'effect':'',
            'index':that.todaygoworkindex,
          });
        },
        //
        addtodayneedwork:function(){
          var that = this;
          that.todayneedworkindex++
          that.todayneedwork.push({
            'title':'',
            'level':'',
            'memberid':'',
            'times':'',
            'index':that.todayneedworkindex,
          });
        },
        //删除销售目标
        removeselltarget:function(index){
          let that = this;
          var nowin = index;
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.selltarget.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.selltarget));
            }
          });
        },
        //
        removetodaygowork:function(index){
          let that = this;
          var nowin = index;
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.todaygowork.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.todaygowork));
            }
          });
        },
        //删除待办
        removetodayneedwork:function(index){
          let that = this;
          var nowin = index;
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.todayneedwork.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.todayneedwork));
            }
          });
        },
      }
    })
	}


	</script>
</body>
</html>
